package com.iob.coin.controller.kgbuilder;

import com.iob.coin.bl.kgbuilder.KgBuilderService;
import com.iob.coin.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;

@RestController
@CrossOrigin
@RequestMapping("/kgbuilder")
public class KgBuilderController {

    @Autowired
    KgBuilderService kgBuilderService; //new

    @PostMapping("/newKg")
    public ResponseVO createKg(@PathParam("kgName") String kgName) {
        return kgBuilderService.newKG(kgName);
    }

    @GetMapping("/getKgs")
    public ResponseVO getKgs() {
        return kgBuilderService.getKgs();
    }

    @PostMapping("/uploadFile")
    public ResponseVO uploadFile(
            @RequestParam("file") MultipartFile multipartFile,
            @RequestParam("kgName") String kgname
    ) {
        return kgBuilderService.uploadFile(multipartFile, kgname);
    }

    @GetMapping("/getDataList")
    public ResponseVO getDataList() {
        //return buildService.getNameAndIdList();
        //传入用户的id，获取用户知识图谱name和id的list<String[]>
        //name:String[0]   kgId:String[1]
        //System.out.println(responseVO.getContent());
        return kgBuilderService.getNameAndIdList();
    }

    @RequestMapping("/loadData")
    public ResponseVO loadData(@PathParam("kgId") int kgId) {
        //传入一个kd的id,返回一个responseVO,里面内容是kgInfoVO
        return kgBuilderService.createKg(kgId);
    }

    @RequestMapping("/deleteKg")
    public ResponseVO deleteKgById(@PathParam("kgId") int kgId) {
        //传入一个kgId，删除对应的kg
        return kgBuilderService.deleteKg(kgId);
    }
}